import 'package:flutter/material.dart';
import 'package:flutter_base/base/base_container.dart';
import 'package:flutter_base/page/img_picker_page.dart';
import 'package:flutter_base/resource/strings/resource_string.dart';
import 'package:flutter_base/resource/theme/dark_mode_provider.dart';
import 'package:flutter_base/resource/theme/theme_color.dart';
import 'package:flutter_base/resource/theme/theme_icon.dart';
import 'package:flutter_base/utils/loading_utils.dart';
import 'package:flutter_base/utils/route_utils.dart';
import 'package:provider/provider.dart';
import 'package:sp_util/sp_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    Loading.ctx = context;
    WidgetsBinding.instance.addObserver(this);
    _initAsync();
  }

  Future<void> _initAsync() async {
    await SpUtil.getInstance();
    setTheme(context);
  }

  @override
  void didChangePlatformBrightness() {
    super.didChangePlatformBrightness();
    // 设置初始化主题颜色
    setTheme(context);
  }

  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  Widget build(BuildContext context) {
    //需要在此代码块中 切换主题才会生效
    return Consumer<DarkModeProvider>(builder: (context, appInfo, _) {
      return BaseContainer(
        decoration: BoxDecoration(color: g1),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            GestureDetector(
              onTap: () {
                launch(context, ImgPickerPage()).then((value) => print('back'));
              },
              child: Image.asset(
                icon,
                width: 30,
                height: 30,
              ),
            ),
            Text(
              DemoLocalizations.of(context).string_title,
              style: TextStyle(fontSize: 16.sp, color: t1),
            )
          ],
        ),
      );
    });
  }
}
